function substitute(template, data, regexp){
  if(!(Object.prototype.toString.call(data) === "[object Array]")){
    data = [data]
  }
  var ret = [];
  for(var i=0,j=data.length;i<j;i++){
    ret.push(replaceAction(data[i]));
  }
  return ret.join("");
  
  function replaceAction(object){
    return template.replace(regexp || (/\\?\{([^}]+)\}/g), function(match, name){
     if (match.charAt(0) == '\\') return match.slice(1);
     return (object[name] != undefined) ? object[name] : '';
    });
  }
}
function insertAfter(newElement,targetElement) {   
	var parent = targetElement.parentNode;   
	if (parent.lastChild == targetElement) {   
		parent.appendChild(newElement);   
	} else {   
		parent.insertBefore(newElement,targetElement.nextSibling);   
	}
}
function getOffsetX(obj,event){
	var event = event || window.event;
	var w1 = event.offsetX;
	var w = parseInt(obj.clientWidth);
	return (w1/w);
}
function timeFormat(time){
	var m1 = Math.floor(time/60)+"";
	if (m1.length<2){m1 = "0" + m1;}
	var m2 =  Math.floor(time - m1*60)+"";
	if (m2.length<2){m2 = "0" + m2;}
	var time = m1 + ":" + m2;
	return time;
}
function lTrim(s){  
	var flg = 0;  
	var lstr = '';  
	while((s.charCodeAt(flg) == 32) || s.charCodeAt(flg) == 12288) {flg++};  
	for(var index = 0; index < s.length - flg; index++)  
		lstr += s.charAt(flg+index);  
	return lstr;  
}  
function rTrim(s){  
	var flg = 0;  
	var rstr = '';  
	var strLength = s.length;  
	while((s.charAt(strLength-1-flg) == ' ') || (s.charAt(strLength-1-flg) == '　')){flg++};  
	for(var index = 0; index < s.length - flg; index++)  
		rstr += s.charAt(index);  
	return rstr;  
} 
function json2Obj(astr){
	var ljson;
	if(typeof astr == "object"){
		return astr;
	}
	astr = (astr != null) ? astr.split("\n").join("").split("\r").join("") : "";
	if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(astr.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) {
		if (astr != "") {
			ljson = eval('(' + astr + ')');
			return ljson;
		}
	}
	return {};
}